package com.happyfamily.springboot.crowdsourcingplatform.service.wang.impl;

import com.happyfamily.springboot.crowdsourcingplatform.base.result.Results;
import com.happyfamily.springboot.crowdsourcingplatform.dao.wang.VerifyWorkDao;
import com.happyfamily.springboot.crowdsourcingplatform.model.Work;
import com.happyfamily.springboot.crowdsourcingplatform.service.wang.VerifyWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

@Service
public class VerifyServiceImpl implements VerifyWorkService
{

	@Autowired
	private VerifyWorkDao verifyWorkDao;
	//作品管理表格显示
	@Override
	public Results<Work> workDeploy(Integer startP, Integer endP, String workname, String starttime, String endtime, String verifyStatus)
	{
		return Results.success(verifyWorkDao.workDeployCount(workname,starttime,endtime,verifyStatus).intValue(),verifyWorkDao.workDeployList(startP,endP,workname,starttime,endtime,verifyStatus));
	}


	//作品审核不通过
	@Override
	public String workNo(String wid, String fname, String wuseraccount)
	{
		String res="error";
		int index=verifyWorkDao.workVerify(wid,"未过审");
		if (index>0)
		{
			File f= new File("src/main/resources/doc");
			File file=new File(f.getAbsolutePath()+"/"+wuseraccount+"/"+fname);
			file.delete();
			res="success";
		}
		return res;
	}

	//作品审核通过
	@Override
	public String workYes(String wid)
	{
		String res="error";
		int index=verifyWorkDao.workVerify(wid,"已审核");
		if (index>0)
		{
			res="success";
		}
		return res;
	}

	//查看作品详情
	@Override
	public Work workDetails(String wid)
	{
		return verifyWorkDao.workDetails(wid);
	}

	//对作品进行删除
	@Override
	public String workDetele(String wid)
	{
		String res="error";
		int index=verifyWorkDao.workDelete(wid);
		if (index>0)
		{
			res="success";
		}
		return res;
	}
}
